#include <cstdio>
#include "../m_incl/epub_dukpt.h"

#define LOGINFO(row) printf("%s\n", row)
#define LOGARRAY(in, inLen)                                                                        \
  for (int i = 0; i < inLen; ++i) {                                                                \
    printf("%02X", in[i]);                                                                         \
  }                                                                                                \
  printf("\n");

constexpr static unsigned char KSI[] = {0x9, 0x99, 0x99};
constexpr static unsigned char DID[] = {0x8, 0x68, 0xAC};
constexpr static unsigned char BDK[] = {0x62, 0xE0, 0xB5, 0xDA, 0xB0, 0xD3, 0x9D, 0x8F, 0xE3, 0x2A,
  0x6B, 0x76, 0x3D, 0xEA, 0x13, 0x46};

int main() {
  auto &&context = EpubDukptContextNew();
  auto &&dukpt   = EpubDukptNew(context);

  unsigned char iksn[10];
  unsigned char ipek[16];
  unsigned char ikcv[8];

  EpubDukptBDK(context, BDK, sizeof(BDK));
  EpubDukptKSI(context, KSI, sizeof(KSI));

  if (!EpubDukptDisperse(dukpt, DID, iksn, ipek, ikcv)) {
    LOGINFO("disperse failed");
    return -1;
  }

  LOGINFO("IKSN:");
  LOGARRAY(iksn, EpubDukptIksnBytes());
  LOGINFO("IPEK:");
  LOGARRAY(ipek, EpubDukptIpekBytes());
  LOGINFO("IKCV:");
  LOGARRAY(ikcv, EpubDukptIkcvBytes());
  return 0;
}
